package com.tengju.bff;

import com.tengju.data.domain.model.alert.AlertEvent;
import com.tengju.data.domain.model.alert.AlertService;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Slf4j
@EnableAsync
@EnableSwagger2
@SpringBootApplication(
        scanBasePackages = {"com.tengju.*", "com.idanchuang.*"},
        exclude = {DataSourceAutoConfiguration.class}
)
@MapperScan(basePackages = {"com.tengju.export.infrastructure.persistence.mapper"},
        sqlSessionFactoryRef = "exportSqlSessionFactoryBean",
        sqlSessionTemplateRef = "exportSqlSessionTemplate"
)
@EnableFeignClients(basePackages = {"com.idanchuang.*"})
public class TengjuApplication {

    static {
        System.setProperty("es.set.netty.runtime.available.processors", "false");
    }

    public static void main(String[] args) {
        long startTime = System.currentTimeMillis();
        ConfigurableApplicationContext applicationContext = SpringApplication.run(TengjuApplication.class, args);
        AlertService alertService = applicationContext.getBean(AlertService.class);
        AlertEvent alertEvent = new AlertEvent("spring容器启动完成：");
        alertEvent.addItem("启动耗时", System.currentTimeMillis() - startTime + " ms");
        alertService.alert(alertEvent);
    }
}
